package com.cxria.shiro.service.impl;


import com.cxria.shiro.entity.Permission;
import com.cxria.shiro.repository.PermissionRepository;
import com.cxria.shiro.repository.RolePermissionRepository;
import com.cxria.shiro.service.ShiroPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShiroPermissionServiceImpl implements ShiroPermissionService {

    @Autowired
    private PermissionRepository permissionRepository;

    @Autowired
    private RolePermissionRepository rolePermissionRepository;

    @Override
    public Permission getByName(String permissionName) {
        return permissionRepository.findByPermissionName(permissionName);
    }

    @Override
    public Permission getById(long id) {
        return permissionRepository.findOne(id);
    }

    @Override
    public List<Permission> getAll() {
        return permissionRepository.findAll();
    }

    @Override
    public List<Permission> getByRoleId(Long roleId) {
        return rolePermissionRepository.findPermissionByRoleId(roleId);
    }

}
